﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.HCLoad.Controls;

namespace YArchitech.Revit.MEP.Opening
{
	public partial class DlgCombineConfig : System.Windows.Forms.Form
	{
		public DlgCombineConfig()
		{
			this.InitializeComponent();
			this.ReadAxisData();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.txtSize.Text != "" && this.txtLength.Text != "")
			{
				this.Size = Convert.ToDouble(this.txtSize.Text);
				this.Length = Convert.ToDouble(this.txtLength.Text);
				this.IsBox = true;
				this.SaveAxisData();
				base.DialogResult = DialogResult.OK;
				return;
			}
			MessageBox.Show("请正确输入参数。");
		}

		private void SaveAxisData()
		{
			FileStream fileStream = new FileStream(Path.GetTempPath() + "OpeningCombine.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			string value = Convert.ToString(this.txtSize.Text);
			streamWriter.WriteLine(value);
			value = Convert.ToString(this.txtLength.Text);
			streamWriter.WriteLine(value);
			streamWriter.WriteLine(this.rbBox.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private bool ReadAxisData()
		{
			string text = Path.GetTempPath() + "OpeningCombine.dat";
			FileInfo fileInfo = new FileInfo(text);
			if (!File.Exists(text))
			{
				return false;
			}
			FileStream fileStream = new FileStream(text, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			try
			{
				streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
				string text2 = streamReader.ReadLine();
				this.txtSize.Text = text2;
				text2 = streamReader.ReadLine();
				this.txtLength.Text = text2;
				text2 = streamReader.ReadLine();
				if (Convert.ToBoolean(text2))
				{
					this.rbBox.Checked = true;
					this.rbArc.Checked = false;
				}
				else
				{
					this.rbBox.Checked = false;
					this.rbArc.Checked = true;
				}
				streamReader.Close();
				fileStream.Close();
			}
			catch (Exception)
			{
				streamReader.Close();
				fileStream.Close();
				fileInfo.Delete();
			}
			return true;
		}

		public new double Size;

		public double Length;

		public bool IsBox;
	}
}
